<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/12/19 0019
 * Time: 下午 2:45
 */

$file = 'flock.txt';
$fp = fopen($file, 'r');


if(flock($fp, LOCK_EX|LOCK_NB)){            // 取得独占锁
    fwrite($fp, "How Are You\r\n");         // 写入数据
    fwrite($fp, "Show Me The Money\r\n");   // 写入数据
    flock($fp, LOCK_UN);                    // 解锁
}else{
    echo 'file locked   我不等待了 我直接去隔壁买包子';
}

fclose($fp);